package cn.getech.data.development.controller.api;

import cn.getech.data.development.api.JobDepHistoryApi;
import cn.getech.data.development.entity.JobDepHistory;
import cn.getech.data.development.service.JobDepRunHistoryService;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName ConfConnectApiController
 * @Description TODO
 * @Author Getech
 * @Date 2020/12/24 11:46
 */
@RestController
public class JobDepHistoryApiController implements JobDepHistoryApi {

    @Autowired
    private JobDepRunHistoryService jobDepRunHistoryService;

    @Override
    public void save(JobDepHistory jobDepHistory) {
        jobDepRunHistoryService.save(jobDepHistory);
    }

    @Override
    public JobDepHistory getOne(JobDepHistory jobDepHistorySearchData) {
        QueryWrapper<JobDepHistory> jobDepHistoryQueryWrapper = new QueryWrapper<>();
        if(null != jobDepHistorySearchData){
            jobDepHistoryQueryWrapper.eq(StringUtils.isNotEmpty(jobDepHistorySearchData.getOozieJobId()),"oozie_job_id",jobDepHistorySearchData.getOozieJobId());
            jobDepHistoryQueryWrapper.eq(null != jobDepHistorySearchData.getJobDepId(),"job_dep_id",jobDepHistorySearchData.getJobDepId());
            List<JobDepHistory> list = jobDepRunHistoryService.list(jobDepHistoryQueryWrapper);
            if(CollectionUtil.isNotEmpty(list)){
                return list.get(0);
            }
        }
        return null;
    }

    @Override
    public void saveOrUpdate2(JobDepHistory jobDepHistory) {
        jobDepRunHistoryService.saveOrUpdate2(jobDepHistory);
    }
}
